#include "FrameController.h"
#include "Device.h"

FrameController* FrameController::m_pInstance = 0;

FrameController::FrameController()
{
	m_iDeltaTimeLimit = FPS_LIMIT;
}


FrameController::~FrameController()
{
}


void FrameController::setFPSLimit(UINT32 fps_limit)
{
	m_iFPSLimit = fps_limit;
	m_iDeltaTimeLimit = 1000 / fps_limit;
}


void FrameController::startTimer()
{
	m_iStartTime = Device::getInstance()->getTime();
}


void FrameController::endTimer()
{
	long end_time = Device::getInstance()->getTime();
	int delta_time = end_time - m_iStartTime;
	if (delta_time < m_iDeltaTimeLimit)
	{
		m_iDeltaTime = m_iDeltaTimeLimit;
		Device::getInstance()->wait(m_iDeltaTimeLimit - delta_time);
	}
	else
	{
		m_iDeltaTime = delta_time;
	}
}

